<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const reverse = (x) => {
            let res = 0;
            while (x !== 0) {
                const digit = x % 10;
                x = ~~(x / 10)
                res = res * 10 + digit
                if (x > Math.pow(2, 31) - 1 || x < Math.pow(-2, 31)) {
                    res = 0
                }
            }
            return res
        }
        console.log(reverse(123));
    </script>
</body>

</html>